<template>
    <div id="pmw_lsdd">
        <!--选项卡插件-->
        <el-tabs id="p_lsdd_box" type="border-card" v-model="whichTab">
            <el-tab-pane label="历史订单">
                <div class="p_table">
                    <el-table
                            :data="searchData"
                            style="width: 100%"
                            :default-sort="{prop: 'createTime', order: 'descending'}"
                            height="500"
                            :stripe=true
                            :border=true
                            :header-cell-style="{backgroundColor:'#409EFF',textAlign:'center',color:'white'}"
                            :cell-style="{textAlign:'center'}"
                    >
                        <el-table-column
                                prop="id"
                                label="订单号"
                                sortable
                                min-width="20%">
                        </el-table-column>
                        <el-table-column
                                prop="createBy"
                                sortable
                                label="创建者编号"
                                min-width="20%">
                        </el-table-column>
                        <el-table-column
                                prop="createTime"
                                sortable
                                label="创建时间"
                                min-width="20%">
                        </el-table-column>
                        <el-table-column
                                prop="orderType"
                                sortable
                                label="订单类型"
                                min-width="20%">
                        </el-table-column>
                        <el-table-column
                                prop="totalPrice"
                                sortable
                                label="订单金额/元"
                                min-width="20%">
                        </el-table-column>
                    </el-table>
                </div>
                <!--交易金额总计-->
                <div class="p_total">交易金额总计：<span>{{sumMoney}}</span>元</div>
            </el-tab-pane>
            <el-tab-pane label="补打订单">
                <div class="p_form">
                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                        <el-form-item label="订单编号">
                            <el-input v-model="ruleFormId" :disabled=true></el-input>
                        </el-form-item>
                        <el-form-item label="订单创建者" prop="createBy">
                            <el-input v-model="getLoginer" :disabled=true></el-input>
                        </el-form-item>
                        <el-form-item label="创建时间" prop="createTime">
                            <el-col :span="11">
                                <el-date-picker type="date" :picker-options=pickerOptions value-format="yyyy-MM-dd"
                                                placeholder="选择日期" v-model="ruleForm.createTime"
                                                style="width: 100%;"></el-date-picker>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="订单类型" prop="orderType">
                            <el-select v-model="ruleForm.orderType" placeholder="请选择订单类型">
                                <el-option label="补打" value="2"></el-option>
                                <el-option label="堂客" value="0"></el-option>
                                <el-option label="外卖" value="1"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="订单金额" prop="totalPrice">
                            <el-input type="number" placeholder="请输入订单金额：/元" v-model="ruleForm.totalPrice"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
                            <el-button @click="resetForm('ruleForm')">重置</el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </el-tab-pane>
        </el-tabs>
        <!--搜索框部分-->
        <div class="p_search clear">
            <div>
                <el-input v-model="searchValue" placeholder="请输入创建者编号"></el-input>
            </div>
            <div>
                <el-button type="primary" @click="searchPerson">搜索</el-button>
            </div>
        </div>
    </div>
</template>

<script>
    import axios from 'axios'

    export default {
        name: "pmw_lsdd",
        data() {
            return {
                whichTab: '0',
                searchValue: '',
                searchData: [],
                total: 0,
                ruleForm: {
                    id: '',/*订单id*/
                    createBy: '',/*创建者ID*/
                    createTime: '',/*创建时间*/
                    orderType: '',/*订单类型*/
                    totalPrice: '',/*订单金额*/
                },
                rules: {
                    /*id:为自动编号*/
                    /*createBy:为登录人员的id*/
                    createTime: [
                        {required: true, message: '请选择创建日期', trigger: 'blur'}
                    ],
                    orderType: [
                        {required: true, message: '请选择订单类型', trigger: 'blur'}
                    ],
                    totalPrice: [
                        {required: true, message: '请输入订单金额', trigger: 'blur'},
                    ],
                },
                /*设置今天之后的时间不可选*/
                pickerOptions: {
                    disabledDate(time) {
                        return time.getTime() > Date.now() - 8.64e6;//如果没有后面的-8.64e6就是不可以选择今天的
                    }
                },
            }
        },
        methods: {
            searchPerson() {
                /*发起查询请求*/
                let data = {
                    "number": this.searchValue,
                    "pager": {
                        "currentPage": 1,
                        "pageSize": 10
                    }
                };
                axios({
                    url: '/api/rms/finance/order/query',
                    method: 'post',
                    params: data,
                    transformRequest: [function () {
                        return JSON.stringify(data)
                    }],
                    headers: {
                        'Content-Type': 'application/json;'
                    },
                }).then(res => {
                    this.searchData = res.data.info
                });

                /*跳转到展示页面*/
                this.whichTab = '0';
            },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        /*表单信息填写完整，发起请求*/
                        console.log(this.ruleForm);
                    } else {
                        /*表单信息不符合规则*/
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        },
        computed: {
            sumMoney() {
                this.total = 0;
                if (this.searchData.length > 0) {
                    this.searchData.map(item => this.total += item.totalPrice)
                }
                return this.total;
            },
            ruleFormId() {
                let time = new Date().toLocaleString('chinese', {hour12: false});
                this.ruleForm.id = time.replace(/[^0-9]/ig, "");
                return this.ruleForm.id;
            },
            getLoginer() {
                /*未完成代码*/
                /*代码说明：这里用于获取登录者id*/
                let loginId = this.$store.state.user.userName;
                this.ruleForm.createBy = loginId;
                return this.ruleForm.createBy;
            }
        },
        created() {
            let data = {
                "number": "",
                "pager": {
                    "currentPage": 1,
                    "pageSize": 10
                }
            };
            axios({
                url: '/api/rms/finance/order/query',
                method: 'post',
                params: data,
                transformRequest: [function () {
                    return JSON.stringify(data)
                }],
                headers: {
                    'Content-Type': 'application/json;'
                },
            }).then(res => {
                this.searchData = res.data.info
            })
        }
    }
</script>

<style scoped lang="less">
    .el-button--primary{
        height: 40px;
        padding: 0 20px;
    }
    * {
        margin: 0;
        padding: 0;
    }

    .clear:after {
        content: '';
        clear: both;
        display: block;
    }

    #pmw_lsdd {
        position: relative;
        padding: 20px;
        /*选项卡*/

        #p_lsdd_box {
            /*表格*/

            .p_table {
                padding: 25px 50px;
            }

            /*总计金额*/

            .p_total {
                height: 40px;
                line-height: 40px;
                margin-bottom: 10px;
                padding: 0 50px;
                text-align: right;
                color: #797d85;

                span {
                    color: #67C23A;
                    font-weight: bold;
                    cursor: default;
                }
            }

            /*表单*/

            .p_form {
                padding: 25px 50px;
            }
        }

        /*搜索框*/

        .p_search {
            position: absolute;
            top: 20px;
            right: 20px;
            padding-right: 5px;

            & > div {
                float: left;
                margin-left: 10px;
            }

            div:first-child {
                width: 130px;
            }
        }
    }
</style>
